package com.jxb.permissions;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;


public class PermissionX {
    private static final String TAG = "InvisibleFragment";

    public static void request(FragmentActivity activity, String[] permissions, PermissionCallback callback) {
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        Fragment existedFragment = fragmentManager.findFragmentByTag(TAG);
        InvisibleFragment invisibleFragment;
        if (existedFragment != null) {
            invisibleFragment = (InvisibleFragment) existedFragment;
        } else {
            invisibleFragment = new InvisibleFragment();
            fragmentManager.beginTransaction().add(invisibleFragment, TAG).commitNow();
        }
        invisibleFragment.requestNow(permissions,callback);
    }
}
